<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.tooltip');
?>
<form  method="post" name="adminForm">
    <div id="lop">
        <h2>Danh sách sinh viên</h2><br>
        <div class="lop-left">
            Mã sinh viên : <input name="ma_sv" type="text" id="ma_sv" value="<?php echo $_POST["ma_sv"] ?>" size="10">
        </div>
        <div class="lop-right">
            Hoặc họ tên sinh viên:<input name="ten_sv" type="text" id="ten_sv" value="<?php echo $_POST["ten_sv"] ?>" size="10">
        </div>
        <div class="clear"></div>
        <div class="lop-middle">
            <input type="submit" value="Tìm kiếm">
        </div>
        <?php
        $ma_sv = $_POST["ma_sv"];
        $ten_sv = $_POST["ten_sv"];
        ?>
        <table id="sinhvienList" class="table table-striped">
            <thead>
                <tr>
                    <th class="left">
                        Mã sinh viên
                    </th>
                    <th class="left">
                        Tên sinh viên
                    </th>
                    <th class="left">
                        Email
                    </th>
                    <th class="left">
                        Điện thoại
                    </th>

                    <th class="left">
                        Ảnh
                    </th>
                    <th class="left">
                        Lớp đã học
                    </th>
                </tr>
            </thead>
            <tbody>
                 <?php
                $db = JFactory::getDbo();
                $query = $db->getQuery(true);
                $query->select('*');
                $query->from('#__sinhvien');
                $query->where('ma_sv like"' . $ma_sv . '" OR ten_sv like "' . $ten_sv . '"');
                $db->setQuery($query);
                $rows = $db->loadObjectList();
               foreach ($rows AS $key => $item) {
                    ?>
                <tr >
                       <th>
                            <?php echo $item->ma_sv; ?>
                        </th>
                        <th>
                            <?php echo $item->ten_sv; ?>
                        </th>
                        <th>
                            <?php echo $item->email; ?>
                        </th>
                        <th>
                            0<?php echo $item->dien_thoai; ?>
                        </th>
                        <th>
                            <img src="<?php echo $item->image; ?>" width="100px" />
                        </th>
                    <th>
                        <?php
                        $query1 = $db->getQuery(true);
                        $query1->select('*');
                        $query1->from('#__dangkilop as a');
                        $query1->join('LEFT', '#__sinhvien AS b ON b.ma_sv = a.ma_sv');
                        $query1->where('a.ma_sv='.$item->ma_sv);
                        $db->setQuery($query1);
                        $rows1 = $db->loadObjectList();
                        foreach ($rows1 AS $key1 => $item1) {
                            echo "$item1->ten_hp<br>";
                        }
                        ?>
                    </th>
                </tr>
                     <?php
                }
                ?>
            </tbody>
        </table>
    </div>
</form>